package com.class05.dao.impl;

import com.class05.dao.StudentDao;
import com.class05.pojo.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassDescription:
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/10/30 20:00
 */
@Repository
public class StudentDaoImpl implements StudentDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Student> queryAll() {
        String sql = "select id,name,age,gender,class as classes from students;";
//        query可以放回列表数据
//        BeanPropertyRowMapper就是封装好RowMapper，要求属性名和列名相同即可
        List<Student> studentList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Student.class));
        Logger logger = LoggerFactory.getLogger(StudentDaoImpl.class);
        logger.info("这是dao打印的列表数据",studentList);
        return studentList;
    }
}
